package primary.tree;

/**
 * @Author Elephas
 * @Date 2022/1/8
 **/
public class MaxDepth {

    /*
        解法一：递归迭代
     */
    public int maxDepth(TreeNode root){
        return maxDepthIter(root,0);
    }
    public int maxDepthIter(TreeNode root,int n){
        if(root == null){
            return n;
        }else{
            int left = maxDepthIter(root.left,n+1);
            int right = maxDepthIter(root.right, n+1);
            return left > right ? left : right;

        }
    }
}
